<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link href="${ctxPath!}/layui/css/layui.css" rel="stylesheet" type="text/css">
    <% include("/templates/common/dialog.html"){} %>
</head>
<div style="padding:10px 50px 10px 10px">
    <form id="workerForm" method="post" action="${ctxPath!}/sys/worker/edit" class="layui-form layui-row">
        <div style="margin-bottom:20px;font-size:14px;border-bottom:1px solid #ccc; padding-bottom: 5px;">用户信息</div>
        <div class="layui-col-md6">
            <input type="hidden" name="id" value="${worker.id}"/>
            <input type="hidden" name="clientInfoId" value="${worker.workerInfoId}"/>
            <div class="layui-form-item">
                <label class="layui-form-label">用户名称</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" name="username" value="${worker.username}" lay-verify="required" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">用户账号</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" name="account" value="${worker.account}" lay-verify="required" />
                </div>
            </div>
            <% if(worker.id == null || worker.id <= 0){ %>
            <div class="layui-form-item">
                <label class="layui-form-label">用户密码</label>
                <div class="layui-input-block">
                    <input class="layui-input" id="password" type="password" name="password" lay-verify="required" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">确认密码</label>
                <div class="layui-input-block">
                    <input class="layui-input" id="r_password" type="password" name="r_password" lay-verify="required" />
                </div>
            </div>
            <% } %>
            <!--如果是机构管理员则显示相应角色,如果是超级管理员则显示机构,选择完机构之后再ajax回调显示相应角色-->
            <div class="layui-form-item">
                <label class="layui-form-label">用户角色</label>
                <div class="layui-input-block">
                    <select name="rid" id="rid">
                        <option value=""></option>
                        <%
                        for(role in roles!){
                        %>
                        <option value="${role.id}" ${worker.rid == role.id ? "selected" : ""}>${role.name}</option>
                        <%
                        }
                        %>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">电话</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" name="telephone" value="${worker.telephone}" lay-verify="required" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">住址</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" name="address" value="${worker.address}" lay-verify="required" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">生日</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" id="birthday" name="birthday" value="${worker.birthday!,dateFormat="yyyy-MM-dd"}" lay-verify="required"  readonly/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" name="email" value="${worker.email}" lay-verify="required" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">自我介绍</label>
                <div class="layui-input-block">
                    <textarea name="introduction" placeholder="请输入内容" class="layui-textarea">${worker.introduction}</textarea>
                </div>
            </div>
        </div>
        <div class="layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">职位</label>
                <div class="layui-input-block">
                    <select name="job" id="job">
                        <option value=""></option>
                        <%
                        for(job in jobs!){
                        %>
                        <option value="${job.id}" ${worker.job == job.id ? "selected" : ""}>${job.name}</option>
                        <%
                        }
                        %>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">籍贯</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" name="nativePlace" value="${worker.nativePlace}" lay-verify="required" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">年龄</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" name="age" value="${worker.age}" lay-verify="required" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">星座</label>
                <div class="layui-input-block">
                    <select name="constellation" id="constellation">
                        <option value=""></option>
                        <option value="白羊座" ${worker.constellation == "白羊座" ? "selected" : ""}>白羊座</option>
                        <option value="金牛座" ${worker.constellation == "金牛座" ? "selected" : ""}>金牛座</option>
                        <option value="双子座" ${worker.constellation == "双子座" ? "selected" : ""}>双子座</option>
                        <option value="巨蟹座" ${worker.constellation == "巨蟹座" ? "selected" : ""}>巨蟹座</option>
                        <option value="狮子座" ${worker.constellation == "狮子座" ? "selected" : ""}>狮子座</option>
                        <option value="处女座" ${worker.constellation == "处女座" ? "selected" : ""}>处女座</option>
                        <option value="天秤座" ${worker.constellation == "天秤座" ? "selected" : ""}>天秤座</option>
                        <option value="天蝎座" ${worker.constellation == "天蝎座" ? "selected" : ""}>天蝎座</option>
                        <option value="射手座" ${worker.constellation == "射手座" ? "selected" : ""}>射手座</option>
                        <option value="摩羯座" ${worker.constellation == "摩羯座" ? "selected" : ""}>摩羯座</option>
                        <option value="水瓶座" ${worker.constellation == "水瓶座" ? "selected" : ""}>水瓶座</option>
                        <option value="双鱼座" ${worker.constellation == "双鱼座" ? "selected" : ""}>双鱼座</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">学历</label>
                <div class="layui-input-block">
                    <select name="education" id="education">
                        <option value=""></option>
                        <%
                        for(education in educations!){
                        %>
                        <option value="${education.value}" ${worker.education.value! == education.value ? "selected" : ""}>${education.desc}</option>
                        <%
                        }
                        %>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">工作经验</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" name="experience" value="${worker.experience}" lay-verify="required" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否已婚</label>
                <div class="layui-input-block">
                    <select name="married" id="married">
                        <option value=""></option>
                        <option value="1" ${worker.married == true ? "selected" : ""}>是</option>
                        <option value="0" ${worker.married == false ? "selected" : ""}>否</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">入职状态</label>
                <div class="layui-input-block">
                    <select name="entryStatus" id="entryStatus">
                        <option value=""></option>
                        <option value="1" ${worker.entryStatus == true ? "selected" : ""}>入职</option>
                        <option value="0" ${worker.entryStatus == false ? "selected" : ""}>已离职</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">员工等级</label>
                <div class="layui-input-block">
                    <select name="workerLevel" id="workerLevel">
                        <option value=""></option>
                        <%
                        for(workerLevel in workerLevels!){
                        %>
                        <option value="${workerLevel.id}" ${worker.workerLevel.value! == workerLevel.id ? "selected" : ""}>${workerLevel.name}</option>
                        <%
                        }
                        %>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center;">
            <div class="layui-input-block">
                <button id="submitButton" class="layui-btn" lay-submit lay-filter="*">保存</button>
                <button type="button" class="layui-btn layui-btn-primary" onclick="closeAll()">取消</button>
            </div>
        </div>
    </form>
</div>
<script src="${ctxPath!}/jquery/jquery.min.js"></script>
<script src="${ctxPath!}/layui/layui.js"></script>
<script src="${ctxPath!}/jqgrid/jquery.jqGrid.minffe4.js?0820"></script>
<script src="${ctxPath!}/jqgrid/myjqGrid.js?v=1.0.1"></script>
<script type="text/javascript">
    layui.use(['form','laydate'], function(){
        var form = layui.form;
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#birthday' //指定元素
        });
        form.on('submit(*)', function(data){
            var workerId = '${worker.id}';
            if(!workerId){
                if($('#password').val() != $('#r_password').val()){
                    layer.alert("两次输入的密码不相同", {
                        icon: 2,
                        skin: 'layer-ext-moon'
                    });
                    return false;
                }
            }
            $.post($("#workerForm").attr("action"), $("#workerForm").serialize(), function(data){
                if(data.status == 200){
                    layer.alert(data.msg, {
                        icon: 1,
                        skin: 'layer-ext-moon'
                    },function () {
                        parent.myJqGrid.reloadGrid({});
                        parent.layer.closeAll();
                    });
                }else{
                    layer.alert(data.msg, {
                        icon: 2,
                        skin: 'layer-ext-moon'
                    });
                }
            });
            return false; //阻止表单跳转。
        });
        form.on('select(orgId)', function(data){
            console.log(data.elem); //得到select原始DOM对象
            console.log(data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象
            $.post("/sys/role/getRoles",{"orgId":data.value},function(data){
                var html="";
                var roles=data.roles;
                for(var i=0;i<roles.length;i++){
                    html+='<option value="'+roles[i].id+'">'+roles[i].name+'</option>';
                }
                $("#rid").html(html);
                form.render('select'); //刷新select选择框渲染
            },"json");
        });
    });
    function closeAll() {
        parent.layer.closeAll();
    }
</script>